package com.qqzone.controller;

import com.qqzone.pojo.Reply;
import com.qqzone.pojo.Topic;
import com.qqzone.pojo.UserBasic;
import com.qqzone.service.ReplyService;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * @author Yang
 * @creat 20:08 2022/8/28
 * @sice 1.8
 */

public class ReplyController {
    private ReplyService replyService = null;


    public String addReply(String content, Integer topicId, javax.servlet.http.HttpSession session) {

        // session 中
        // friend 保存的是 当前topic的主人信息
        // userBasic 保存的是 当前使用者的信息

        // 其中 topic中的author == friend，不等于userBasic
        UserBasic author = (UserBasic) session.getAttribute("userBasic");
        Reply reply = new Reply(content, new Date(), author, new Topic(topicId));
        replyService.addReply(reply);
        return "redirect:topic.do?operate=topicDetail&id="+topicId;
    }

    public String delReply(Integer replyId, Integer topicId) {
        replyService.delReply(replyId);
        // 重新发请求，渲染 detail 页面
        return "redirect:topic.do?operate=topicDetail&id=" + topicId;
    }
}
